#include "field_factory.h"
#include "protocol_field.h"

CFieldFactory::CFieldFactory()
{

}

CFieldFactory::~CFieldFactory()
{

}

void CFieldFactory::DeleteFiled(CProtocolFieldBase*& filed)
{
	if (filed == nullptr) return;
	delete filed;
	filed = nullptr;
}

CProtocolFieldBase* CFieldFactory::NewFiled(int type)
{
	CProtocolFieldBase* field = nullptr;
	switch (type)
	{
	case PFT_BOOL:
		field = new CProtocolFieldBool();
		break;
	case PFT_CHAR:
		field = new CProtocolFieldChar();
		break;
	case PFT_UCHAR:
		field = new CProtocolFieldUChar();
		break;
	case PFT_INT:
		field = new CProtocolFieldInt();
		break;
	case PFT_UINT:
		field = new CProtocolFieldUInt();
		break;
	case PFT_LONG:
		field = new CProtocolFieldLong();
		break;
	case PFT_ULONG:
		field = new CProtocolFieldULong();
		break;
	case PFT_SHORT:
		field = new CProtocolFieldShort();
		break;
	case PFT_USHORT:
		field = new CProtocolFieldUShort();
		break;
	case PFT_FLOAT:
		field = new CProtocolFieldFloat();
		break;
	case PFT_DOUBLE:
		field = new CProtocolFieldDouble();
		break;
	case PFT_INT64:
		field = new CProtocolFieldInt64();
		break;
	case PFT_UINT64:
		field = new CProtocolFieldUInt64();
		break;
	case PFT_STRING:
		field = new CProtocolFieldChar();
		break;
	case PFT_CHAR_ARRAY:
		field = new CProtocolFieldCharArray();
		break;
	case PFT_STRUCT:
		field = new CProtocolFieldStruct();
		break;
	case PFT_PAIR:
		field = new CProtocolFieldStlPair();
		break;
	case PFT_LIST:
	case PFT_VECTOR:
	case PFT_DEQUE:
	case PFT_SET:
	case PFT_MUTILSET:
		field = new CProtocolFieldStlOneKeyList(type);
		break;
	case PFT_MAP:
	case PFT_MUTILMAP:
		field = new CProtocolFieldStlMap();
		break;
	case PFT_DynamicBuff:
		field = new CProtocolFieldDynamicBuf();
		break;
	case PFT_UNKNOW:
		field = new CProtocolFieldUNknown();
		break;
	default:
		break;
	}

	return field;
}

CProtocolFieldBase* CFieldFactory::NewFiledByType(const std::string& type_str)
{

	return nullptr;
}
